const fileService = require("../service/fileService"),
    utils = require("../utils");

class FileController {
    //上传文件
    async upload(req, res, next) {
        try {
            const result = await fileService.create({
                id: utils.getSnowId(),
                ...req.file,
            });
            res.send(
                utils.msgSuccess({
                    data: {
                        ...result,
                        download_url: `http://${process.env.HOST}:${process.env.PORT}/uploads/${result.file_url}`,
                    },
                })
            );
        } catch (error) {
            next(error);
        }
    }
}
module.exports = new FileController();
